<?php
/**
 * Created by PhpStorm.
 * User: Lin
 * Date: 2017/3/1 0001
 * Time: 下午 14:37
 */
Class CategoryAction extends CommonAction{
    
    //分类首页视图
    public function index(){
        $this->display();
    }
    
    //显示分类列表
    public function showList(){
        import('Class.Category',APP_PATH);
        $this->cate=Category::unlimitedForLevel(M('cate')->order('sort DESC')->select());
        $this->display();
    }
    
    //添加分类
    public function addCate(){
        import('Class.Category',APP_PATH);
        $this->cate= Category::formatCateLevel(M('cate')->select());
        $this->display();
    }
    
    //运行添加分类
    public function runAddCate(){
        if (M('cate')->add($_POST)){
            $this->success('添加成功');
        }else{
            $this->error('添加失败');
        }
    }
    
    //删除分类
    public function removeCate(){
        if (M('cate')->delete($_GET['id'])){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    //显示编辑分类视图
    public function editCate(){
        $cat=M('cate')->find($_GET['id']);
        import('Class.Category',APP_PATH);
        $this->cat=$cat;
        $this->cate= Category::formatCateLevel(M('cate')->select(),$cat['parent_id']);
        $this->display();
    }

    //运行编辑分类
    public function runEditCate(){
        if (M('cate')->save($_POST)){
            $this->success('编辑成功',U(GROUP_NAME.'/Category/showList'));
        }else{
            $this->error('编辑失败');
        }
    }


}